package com.gddb.xwj.mywiki.controller;

import com.gddb.xwj.mywiki.req.EbookQueryReq;
import com.gddb.xwj.mywiki.req.EbookSaveReq;
import com.gddb.xwj.mywiki.resp.CommonResp;
import com.gddb.xwj.mywiki.resp.EbookQueryResp;
import com.gddb.xwj.mywiki.resp.PageResp;
import com.gddb.xwj.mywiki.service.EbookService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 描述：
 *
 * @author xwj
 * @create 2022-03-18 19:17
 */
@RestController
@RequestMapping("/ebook")
public class EbookController {

    @Resource
    private EbookService ebookService;

    @GetMapping("/list")
    public CommonResp list(EbookQueryReq req){
        CommonResp<PageResp<EbookQueryResp>> resp = new CommonResp<>();
        PageResp<EbookQueryResp> cont = ebookService.list(req);
        resp.setContent(cont);
        return resp;
    }

    @PostMapping("/save")
    public CommonResp save(@Valid @RequestBody EbookSaveReq req){
        CommonResp resp = new CommonResp<>();
        ebookService.save(req);
        return resp;
    }

    /**
     * /{id} 用 @PathValiable接收
     * JSON 用 @RequestBody接收
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public CommonResp delete(@PathVariable Long id){
        CommonResp<Object> resp = new CommonResp<>();
        ebookService.delete(id);
        return resp;
    }
}
